home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10323 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Limiting stdin input to "n" chars
  5. Date: 16 Mar 1996 20:17:10 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4if7k6$9ro@news.xs4all.nl>
  8. References: <4hqfmc$un7@thorn.cc.usm.edu> <4icer1$df5@altrade.nijmegen.inter.nl.net>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. Auke.Reitsma@net.HCC.nl (Auke Reitsma) writes:
  13.  
  14. >rmfulce@ocean.st.usm.edu (Mike Fulce) wrote:
  15.  
  16. >> How do you limit the number of characters read from stdin?  What I want to do 
  17. >> is to automatically do a carriage return after a user enters say.. 2 digits.  
  18. >> I've written a few programs using scanf to get input, but it won't work for 
  19. >> what I need now. (I think it's because scanf is buffered I/O?).  
  20.  
  21. >Do character by character input with e.g. getch() or getchar()
  22. >/* (Non-ISO/ANSI) */ 
  23.  
  24. getchar() is defined in ANSI C (paragraph 7.9.7.6 if you want to
  25. look it up).
  26.  
  27. >or fgetc( stdin ) /* ISO/ANSI */
  28. >Or use fgets( your_buffer, number_of_chars, stdin ) /* ANSI */
  29.  
  30. No won't work.  fgets() uses the standard I/O library which will
  31. wait for a linefeed anyway.
  32.  
  33. Frank
  34. --
  35. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  36. ------------------------------------------------------------------------
  37. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  38.